<style>
.datepicker{z-index:1151 !important;}
</style>
<script>
$(function(){
	$('.date').datepicker({
		format: 'dd/mm/yyyy',
		todayHighlight: true,
		autoclose:true,
	}).on('changeDate', function(e){
		if(typeof e.date != 'undefined'){
			var st = e.date.getTime()/1000;
			$('#start_date').val(moment(st*1000).format('YYYY-MM-DD'));
			updateTime(st);
		}
    });
	
	$('#end_date').datepicker({
		format: 'yyyy-mm-dd',
		todayHighlight: true,
		autoclose:true,
	})
	
	var ini_start_date = $('#start_date_show').val();
	if( ini_start_date != ''){
		var st = moment(ini_start_date,'DD/MM/YYYY').toDate().getTime()/1000;
		updateTime(st);
	} 
	
	function updateTime(st){
		$.get('__ROOT__/index.php/Index/getDisableTime?st=' + st,function(data){
			if(data != ''){
				//console.info(JSON.parse( data ));
				$('#start_time').timepicker('option',{ 
					'disableTimeRanges': JSON.parse( data ),
				});
			}
		})
	}
	$('#email').bind('validation', function(evt, isValid) {
		if(isValid){
			$.get('__ROOT__/index.php/Index/getKundenInfo?email=' + encodeURIComponent($('#email').val()),function(data){
				processKundenInfo(data);
			})
		}
    });
	
	setFormValidation();
	
	$('.custom-only').hide();
	$('#therapie_id').change(function(){
		$('.custom-only').hide();
		$('.custom-hide').show();
		$('#end_date').val('');
		var tid = $(this).val();
		$.get('__ROOT__/index.php/Index/getDuration?tid=' + tid,function(data){
			if(data != ''){
				$('#therapie_duration').html(data);
			}
		})
		if(tid == 8){
			// feietag, all day
			$('#start_time').val('08:00');
			$('#start_time').prop('readonly',true);
			autoFill();
		}
		if(tid == 9){
			// custom block
			$('.custom-only').show();
			$('.custom-hide').hide();
			if($('#end_time').val() == ''){
				$('#end_time').val('22:00');
			}
			$('#end_date').val($('#start_date').val());
			autoFill();
		}
	})
	
	function autoFill(){
		$('#email').val('admin@admin.com');
		$('#email').trigger('blur')
	}
	var ini_therapie = $('#therapie_id').val();
	if( ini_therapie != '0'){
		$('#therapie_id').trigger('change');
	}
	$('#alert').hide();
	$('#end_time').timepicker({ 
		'timeFormat': 'H:i',
		'minTime': '8:00am',
		'maxTime': '10:00pm',
		'step':'60'
	});
});
</script>
<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	<h4 class="modal-title" id="myModalLabel">Anmeldung</h4>
  </div>
  <div class="modal-body">
	<form class="form-horizontal" id="orderService" action="__ROOT__/index.php/Index/saveServiceRequest" method="POST">
			<input type="hidden" name="termine_id" id="termine_id" value="{$termin.termine_id}" />
			<div class="form-group">
				<label class="col-sm-2 control-label" for="therapie_id">Therapie<span class="text-danger">*</span></label>
				<div class="col-sm-10">
					<select name="therapie_id" id="therapie_id" class="form-control">
						<option value="0" selected disabled>von Ihnen gewünschte Therapie: </option>
						<volist name="therapies" id="therapie">
						<option value="{$therapie.therapie_id}" 
						<?php 
							if($therapie['therapie_id'] == $termin['therapie_id']){echo "selected";}
						?>
						>{$therapie.therapie_name}</option>
						</volist>
					</select>
				</div>
			</div>
			<div class="form-group custom-hide">
				<label class="col-sm-2 control-label" for="therapie_duration">Dauer<span class="text-danger">*</span></label>
				<div class="col-sm-10">
					<select name="therapie_duration" id="therapie_duration" class="form-control">
						<option value="1" <eq name="termin['duration']" value="1">selected</eq>>1 Stunde</option>
						<option value="2" <eq name="termin['duration']" value="2">selected</eq>>2 Stunden</option>
						<option value="13" <eq name="termin['duration']" value="13">selected</eq>>all day</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="start_date_show" class="col-sm-2 control-label">Datum<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control date" id="start_date_show" name="start_date_show" value="{$start_date_show}">
					<input type="hidden" id="start_date" name="start_date" value="{$start_date}">
				</div>
				<label for="start_time" class="col-sm-2 control-label">Uhr<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control time" id="start_time" name="start_time" data-validation="required" data-validation-error-msg="Pflichtfeld" <notempty name="termin['start']">value="{$termin.start|date='H:s',###}"</notempty>>
				</div>
			</div>
			<div class="form-group custom-only">
				<label for="start_date_show" class="col-sm-2 control-label">Datum<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="end_date" name="end_date" placeholder="end" <notempty name="termin['end']">value="{$termin.end|date='Y-m-d',###}"</notempty>>
				</div>
				<label for="start_time" class="col-sm-2 control-label">Uhr<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control time" id="end_time" name="end_time" placeholder="end" <notempty name="termin['end']">value="{$termin.end|date='H:s',###}"</notempty>>
				</div>
			</div>
			<div class="form-group">
				<label for="email" class="col-sm-2 control-label">Email<span class="text-danger">*</span></label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="email" name="email" value="{$termin.email}" data-validation="email" data-validation-error-msg="E-Mail Adresse Formatfehler.">
					<input type="hidden" id="kunden_id" name="kunden_id" value="{$termin.kunden_id}">
				</div>
			</div>
			<div class="form-group contact">
				<label for="name" class="col-sm-2 control-label">Name<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="name" name="name" value="{$termin.name}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
				<label for="vorname" class="col-sm-2 control-label">Vorname<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="vorname" name="vorname" value="{$termin.vorname}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
			</div>
			<div class="form-group contact">
				<label for="geburtstag_show " class="col-sm-2 control-label">Geburtstag<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control birthday" id="geburtstag_show" name="geburtstag_show" value="{$termin.geburtstag}">
					<input type="hidden" id="geburtstag" name="geburtstag" value="{$termin.geburtstag}">
				</div>
				<label for="beruf" class="col-sm-2 control-label">Beruf<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="beruf" name="beruf" value="{$termin.beruf}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
			</div>
			<div class="form-group contact">
				<label class="col-sm-2 control-label" for="familienstand">Familienstand<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<select name="familienstand" id="familienstand" class="form-control">
						<option value="1" <eq name="termin['familienstand']" value="1">selected</eq>>ledig</option>
						<option value="2" <eq name="termin['familienstand']" value="2">selected</eq>>verheiratet</option>
						<option value="3" <eq name="termin['familienstand']" value="3">selected</eq>>geschieden</option>
						<option value="4" <eq name="termin['familienstand']" value="4">selected</eq>>getrennt lebend</option>
						<option value="5" <eq name="termin['familienstand']" value="5">selected</eq>>verwitwet</option>
					</select>
				</div>
				<label for="anzahl_kinder" class="col-sm-2 control-label">Kinder<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="anzahl_kinder" name="anzahl_kinder" placeholder="Anzahl Ihrer Kinder" value="{$termin.anzahl_kinder}" data-validation="number" data-validation-error-msg="Nummer erforderlich">
				</div>
			</div>
			<div class="form-group contact">
				<label for="address" class="col-sm-2 control-label">Adresse<span class="text-danger">*</span></label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="address" name="address" placeholder="Straße, Hausnr." value="{$termin.address}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
			</div>
			<div class="form-group contact">
				<label for="plz"  class="col-sm-2 control-label">PLZ<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="plz" name="plz" value="{$termin.plz}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
				<label for="land" class="col-sm-2 control-label">Bundesland<span class="text-danger">*</span></label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="land" name="land" value="{$termin.land}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
			</div>
			<div class="form-group contact">
				<label for="telnum" class="col-sm-2 control-label">Telefonnum.<span class="text-danger">*</span></label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="telnum" name="telnum" value="{$termin.telnum}" data-validation="required" data-validation-error-msg="Pflichtfeld">
				</div>
			</div>
			<div class="form-group contact">
				<label for="anliegen" class="col-sm-2 control-label">Anliegen<span class="text-danger">*</span></label>
				<div class="col-sm-10">
					<textarea class="form-control" row="3" id="anliegen" name="anliegen">{$termin.anliegen}</textarea>
				</div>
			</div>
			<div class="checkbox contact">
				<label>
					<input type="checkbox" name="law" id="law" value="1" data-validation="required" data-validation-error-msg="Pflichtfeld"<notempty name="termin">checked</notempty>/>Schweigepflicht und Datenschutz laut § 203 StGB Abs.1 Satz1
				</label>
			</div>
			<div class="alert alert-info">*Absage vor 48Std. eines Termins möglich. Ansonsten wird der Termin nach geplanter Therapieleistung errechnet. Eine Veränderung des Termins erfolgt als Sonderfall per Email.</div>
			<div id="alert" class="alert alert-warning">
			  <span id="resp-alert"></span>
			</div>
		</form>
  </div>
  <div class="modal-footer">
	<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
	<button type="button" class="btn btn-primary contact" id="save-service">Anmelden</button>
	
  </div>